package com.ye.controller;


import com.ye.domain.User;
import com.ye.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
//@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

//    查询全部正常用户账号
    @GetMapping("/all")
    public List<User> queryAll() {
        List<User> users = userService.queryAll();
        return users;
    }

//    通过用户id获取用户信息
    @GetMapping("queryById")
    public User queryUserById(@RequestParam("id") Integer id) {
        return userService.queryUserById(id);
    }

//    通过用户名修改密码

    @GetMapping("updatePassword")
    public void updatePassword(@RequestParam("username") String username,@RequestParam("password") String password) {
        userService.updatePassword(username, password);
    }
//    改变用户账号当前状态

    @GetMapping("/updateState")
    public void updateState(@RequestParam("id") Integer id,@RequestParam("state") String state) {
        userService.updateState(id, state);
    }

    //    新增用户
    @PostMapping("/insertUser")
    public void insertUser(@RequestBody User user) {
        userService.insertUser(user);
    }

//    登录认证
    @PostMapping("/login")
    public User loginAuth(@RequestParam("username") String username,@RequestParam("password") String password){
        return userService.loginAuth(username, password);
    }

}
